package com.andox.fn.inf.rpc.rest.example.provider;

import java.util.List;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

import com.andox.fn.inf.rpc.rest.example.UserService;


public class UserServiceImpl implements UserService {
	private Queue<User> userList = new ConcurrentLinkedQueue<UserService.User>();
	private static AtomicInteger id = new AtomicInteger(1);
	
	@Override
	public User addUser(User user) {
		if (userList.size() > 10) {
			userList.poll();
		}
		
		user.setId(id.getAndIncrement());
		
		userList.offer(user);
		
		return user;
	}

	@Override
	public List<User> list() {
		List<User> u = userList.stream().collect(Collectors.toList());
		return u;
	}

	@Override
	public void doNotExport() {
		System.err.println("shit");
	}
}
